<template>
  <div class="menuNav" @mouseleave="currentIndex = 'flag'">
    <!-- 菜单栏 -->
    <div class="menus-body">
      <div class="menus">
        <div
          @mouseover="currentIndex=index"
          :class="['menus-item',{active:currentIndex===index}]"
          v-for="(item,index) in cities"
          :key="index"
        >
          <span>{{item.type}}</span>
          <em class="el-icon-arrow-right"></em>
        </div>
      </div>
    </div>
    <!-- 详情内容 -->
    <div class="content" v-if="currentIndex != 'flag'">
      <div
        class="contentItem"
        v-if="currentIndex==index"
        v-for="(item,index) in cities"
        :key="index"
      >
        <div
          class="children"
          v-for="(value,i) in item.children"
          :key="i"
          @click="$router.push('/posts?city='+value.city)"
        >
          <div class="num">{{i+1}}</div>
          <span class="cityName">{{value.city}}</span>
          <p class="desc">{{value.desc}}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cities: [],
      currentIndex: 'flag'  //标记当前显示的菜单项  
    }
  },
  mounted() {
    // console.log(this.currentIndex);
    // 获取城市菜单列表  http:127.0.0.1:1337/posts/cities
    this.$axios({
      url: '/posts/cities',
    })
      .then(res => {
        // console.log(res);
        this.cities = res.data.data
      })
  },
  // watch: {
  //   currentIndex() {
  //     console.log(this.currentIndex);
  //   }
  // }
}
</script>
<style lang="less" scoped>
.menuNav {
  width: 260px;
  position: relative;
  .menus {
    border-left: 1px solid #ddd;
    border-top: 1px solid #ddd;
    z-index: 999;
    position: relative;
    .menus-item {
      height: 40px;
      padding: 0 20px;
      font-size: 14px;
      border-bottom: 1px solid #ddd;
      border-right: 1px solid #ddd;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .el-icon-arrow-right {
        font-size: 18px;
        color: #999;
      }
      &.active {
        border-right: 1px solid #fff;
      }
    }
    .menus-item:hover {
      color: #ffa500;
      /deep/ .el-icon-arrow-right {
        color: #ffa500;
      }
    }
  }
  //   详情内容样式
  .content {
    position: absolute;
    width: 350px;
    height: 190px;
    left: 259px;
    top: 0;
    background-color: #fff;
    border: 1px solid #ddd;
    padding-top: 5px;
    z-index: 2;
    .contentItem {
      cursor: pointer;
      .children {
        display: flex;
        align-items: center;
        padding: 8px 10px 8px 20px;
        height: 20px;
        background-color: #fff;
        .num {
          color: #ffa500;
          font-size: 23px;
          font-style: italic;
          margin-right: 15px;
        }
        .cityName {
          color: #ffa500;
          font-size: 14px;
        }
        .cityName:hover,
        .desc:hover {
          text-decoration: underline;
        }
        .desc {
          color: #999;
          font-size: 14px;
          margin-left: 15px;
        }
      }
    }
  }
}
</style>